package com.yyfax.ph.personal.mymoney.cash;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

import java.util.List;

/**
 * Created by xiongyufeng on 2017/11/11.
 * Copyright  2017 www.yylending.com. All Rights Reserved.
 */
public class DrawDetailModel extends Model {
	private static final String TAG = RebateDetailModel.class.getSimpleName();

	protected static final int MSG_REFRESH_WITHDRAW_DETAILS = 6;
	protected static final int MSG_LOAD_MORE_WITHDRAW_DETAILS = 7;

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(DrawDetailModel.Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		return service.getWithDrawList(token, (WithDrawParams) params);
	}

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		WithDrawDetailResult result = cast(obj);
		EventAgent.post(result);
	}

	private interface Service {
		@POST("account/balance/withdrawDetail")
		Observable<WithDrawDetailResult> getWithDrawList(@Header("token") String token, @Body WithDrawParams params);
	}

	public static class WithDrawParams {
		/**
		 * 当页码
		 */
		public int pageNo;
		/**
		 * 页长
		 */
		public int pageSize;
		/**
		 * 开始时间(yyyy/mm/dd)
		 */
		public String startDate;

	}

	public static class DrawInfo {
		/***
		 * 提现日期
		 */
		public String operateDate;
		/***
		 * 提现金额
		 */
		public String amount;
		/***
		 * 提现状态Code 020 提现中 030 提现失败 040 提现成功 050 待返现
		 */
		public String billStatus;
		/***
		 * 提现状态名 020 提现中 030 提现失败 040 提现成功 050 待返现
		 */
		public String billStatusName;
		/***
		 *贷款发放金额
		 */
		public int businesssum;
	}

	public static class DrawDetail {
		/***
		 * 返现笔数
		 */
		public int cnt;
		/***
		 * 提现总额
		 */
		public int amountSum;

		public List<DrawInfo> accountDetailForDrawList;

	}

	public static class WithDrawDetailResult extends BaseResultEntity<DrawDetail> {
	}
}